import java.util.regex.*;

public class RegExDemo {
	public static void main(String[] args) {
		String regExpPartOfName = "(([A-Z][a-z]+)|von|van|of)";
		String regExpName = "name is (" + regExpPartOfName + "\\s)*" + regExpPartOfName;
		Pattern pattern = Pattern.compile(regExpName);
		Pattern patName = Pattern.compile("name is ((\\S+\\s*)+)");

		String emailMessage = "Hi there," + 
		                      "My name is Jack Bauer, and I am trapped " + 
				              "in Africa.  The place name is Dominican Republic " +
		                      "of Congo.";
		
		Matcher matcher = pattern.matcher(emailMessage);
		System.out.println("Email:\n" + emailMessage);
		System.out.println("Pattern:\n" + regExpName);
		while(matcher.find()) {
			String phrase = matcher.group(0);
			System.out.println("Found name in \"" + phrase + "\"");
			Matcher m2 = patName.matcher(phrase);
			while(m2.find())
				for(int i=1; i < m2.groupCount(); i++)
					System.out.println("\t part of name: " + m2.group(i));
		}
	}
}
